<title>登陆日志</title>
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>系统监控</cite></a>
        <a><cite>日志监控</cite></a>
        <a><cite>登陆日志</cite></a>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body layui-form" lay-filter="LAY-maintain-logs-login-searchForm">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="text" name="keywords" placeholder="请输入关键词" class="layui-input">
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="ip" placeholder="IP" class="layui-input">
                </div>
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn" lay-submit lay-filter="LAY-maintain-logs-login-search"> <i class="layui-icon layui-icon-search"></i></button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="LAY-maintain-logs-login-manage" lay-filter="LAY-maintain-logs-login-manage"></table>
            <script type="text/html" id="LAY-maintain-logs-login-toolbar">
                <div class="layui-btn-container">
                    {{# if (AppGeneral.userCan('maintain.logs.login.destroy')){ }}
                    <btton class="layui-btn layui-btn-sm layui-btn-danger" lay-event="deletes"><i class="layui-icon layui-icon-delete"></i></btton>
                    {{# } }}
                </div>
            </script>
        </div>
    </div>
</div>

<script>
    layui.use(['index', 'baseMethods'], function () {
        const {form, layer, table, baseMethods} = layui, tableId = 'LAY-maintain-logs-login-manage';
        const tableIns = baseMethods.table({
            elem: '#'+tableId,
            url: '/maintain/logs/login/list',
            toolbar: '#LAY-maintain-logs-login-toolbar',
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'username', title: '操作用户', width: 150,
                    templet: function (d) {
                        return d.user ? (d.user.username||'--') : '--';
                    }
                },
                {field: 'platform', title: '系统', width: 120},
                {field: 'browser', title: '浏览器', width: 120},
                {field: 'ip', title: 'IP', width: 138},
                {field: 'ip_address', title: 'IP地址'},
                {field: 'message', title: '描述'},
                {field: 'created_at', title: '创建时间', width:190},
            ]]
        });
        let tableTools = {
            deletes: function (obj){
                const hasCheck = table.checkStatus(obj.config.id), hasCheckData = hasCheck.data;
                if (hasCheckData.length > 0){
                    baseMethods.toolOpera({
                        title: `确认删除选中的 ${hasCheckData.length} 项吗？`,
                        request: {
                            url: '/maintain/logs/login/destroy',
                            type: "delete",
                            data: {ids: hasCheckData.map(item => item.id)},
                            success: function (){
                                tableIns.reloadData();
                            }
                        },
                    })
                    return true;
                }
                layer.msg('请选择操作项', {icon:5});
            },
        };
        table.on('toolbar('+tableId+')', function(obj) {
            tableTools[obj.event] ? tableTools[obj.event].call(this, obj) : '';
        });
        form.on('submit(LAY-maintain-logs-login-search)', function(data){
            tableIns.reloadData({
                where: data.field,
                page: {curr:1}
            })
        });
    });
</script>
